<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>信息编辑</title>
        {{include '../shared/_common_top'}}
    </head>
    <body class="gray-bg">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title">信息修改-{{name}}</h3>
                </div>
                <div class="panel-body">
                    <form method="post" action="/admin/blog/update/{{model.id}}" class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <!-- 在html5中 通过设置属性required实现必填 -->
                                <input type="text" required class="form-control" name="title" value="{{model.title}}" placeholder="请输入标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">分类</label>
                            <div class="col-sm-10">
                                <select class="form-control" type="type" id="selType" name="type">
                                    {{each types}}
                                    <option value="{{$value.id}}">{{$value.name}}</option>
                                    {{/each}}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="hidden" name="img" id="ImgUrls" value="{{model.img}}"/>
                        <label class="col-sm-3 control-label no-padding-right">封面图</label>

                        <div class="col-sm-9">
                            <div class="col-xs-4 col-sm-2" id="yl_file_upload">
                            <label style="font-size:30px;" class="fa fa-upload file-label selected" data-title="Change">
                                                <span class="file-name">
                                                    <i class="icon-picture"></i>
                                                </span>
                            </label>
                            </div>
                            <div class="thumbnail col-xs-6 col-sm-3">
                                <img id="m_imgCtrl" style="height: 200px; display: block;" src="{{model.img}}"/>
                            </div>
                        </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">简介</label>
                            <div class="col-sm-10">
                                <textarea name="description" placeholder="请输入简介" class="form-control" cols="30" rows="5">{{model.description}}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10">
                                <textarea name="content" placeholder="请输入内容" class="form-control" cols="30" rows="5">{{model.content}}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <!-- type="submit" 的按钮点击之后会自动触发表单的提交事件 -->
                                <button type="submit" class="btn btn-primary btn-block">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        {{include '../shared/_common_bottom'}}
        <script type="text/javascript">
$(function(){
    $('#selType').val('{{model.type.toString()}}')
})
      </script>
          <script charset="utf-8" src="/lib/kindeditor/kindeditor.min.js"></script>
        <script charset="utf-8" src="/lib/kindeditor/lang/zh-CN.js"></script>
        <script>
            var options = {
                uploadJson: '/common/kindeditor/uploadImg'
            };

            KindEditor.ready(function(K) {
                window.editor = K.create('[name="content"]', options);
            });
            $('.panel-body form').validate({
                rules:{
                    title:{
                    required:true,
                    minlength:2
                    }
                },
                messages:{
                },
                submithande:function(f){
                    editor.sync()
                    f.submit()
                }
            })
    /////////上传控件
    KindEditor.ready(function (K) {
        var editor = K.editor({
            uploadJson: '/common/kindeditor/uploadImg'
        });
        K('#yl_file_upload').click(function () {
            editor.loadPlugin('image', function () {
                editor.plugin.imageDialog({
                    clickFn: function (url) {
                        editor.hideDialog();
                        $("#m_imgCtrl").attr("src", url);
                        $("#ImgUrls").val(url);
                    }
                });
            });
        });
    });


        </script>
    </body>
</html>
